package com.qf.service.impl;

import com.qf.entity.User;
import com.qf.mapper.UserMapper;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zjw
 * @description
 * @date 2021/9/29$ 14:23$
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public String transferMoney(Integer decrementUserId, Integer incrementUserId, Integer money) {
        //1. decrementUserId 减掉 money
        int count = userMapper.decrementMoneyById(decrementUserId, money);
        if (count != 1) {
            System.out.println("扣减用户金额失败！！");
            throw new RuntimeException("扣减用户金额失败！！");
        }

        int i = 1 / 0;

        //2. incrementUserId 加上 money
        count = userMapper.incrementMoneyById(incrementUserId, money);
        if (count != 1) {
            System.out.println("增加用户金额失败！！");
            throw new RuntimeException("增加用户金额失败！！");
        }
        return "SUCCESS";
    }
}
